package priv.lan.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import priv.lan.mapper.UserMapper;
import priv.lan.pojo.User;
import priv.lan.service.UserService;

/**
 * @Description: TODO
 * @author: lan
 * @date: 2021/12/1 15:57
 * @Version: 1.0
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public Boolean isLogin(User user) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<User>();
        queryWrapper.eq("is_deleted", 0);
        queryWrapper.eq("username", user.getUsername()).and(wq->wq.eq("password", user.getPassword()));
        User user1 = userMapper.selectOne(queryWrapper);
        if (user1!=null){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public boolean deletByLogic(String id) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        User user = userMapper.selectOne(queryWrapper);
        if (user!=null){
            user.setIsDeleted(1);
            userMapper.updateById(user);
            return true;
        }else{
            return false;
        }
    }
}
